package com.bootdo.mq;

import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.bootdo.common.utils.DateUtils;

/**
 * @program: bootdo
 * @packageName: com.bootdo.mq
 * @className: SendMsgToUser
 * @description: 发送消息示例
 * @author: Silver2018
 * @create: 2020-03-15 16:53
 */
@Component
public class SendMsgToUser {

    @Autowired
    RabbitUtil rabbitUtil;

    @Lazy(value = false)
    public void sendMsg(){

//        ThreadPoolExecutor executor = new ThreadPoolExecutor(50, 100, 200, TimeUnit.MILLISECONDS,
//                new ArrayBlockingQueue<Runnable>(100));
//
//        for (int i = 1; i <= 100; i++) {
//            String queueName = "topic.payee.user_"+i;
//            JSONObject object = new JSONObject();
//            object.put("queueName",queueName);
//            object.put("code",1);
//            object.put("date", DateUtils.format(new Date(),DateUtils.DATE_TIME_PATTERN));
//            object.put("userId",i);
//            object.put("payType",i);
//            object.put("msg","排队信息发送变化");
//
//            @SuppressWarnings("unused")
//			Future<String> future = executor.submit(() -> {
//                rabbitUtil.sendToQueue(queueName,object.toJSONString());
//                System.err.println("线程 [ " + Thread.currentThread().getName() + " ] 推送消息到MQ成功! " + new Date());
//                return Thread.currentThread().getName();
//            });
//
//        }
    }

}
